package com.mmy.controller.visa;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.domain.sys.TSysUser;
import com.mmy.domain.visa.TVisaOrder;
import com.mmy.domain.visa.VVisaBase;
import com.mmy.service.impl.visa.VisaBaseServiceImpl;
import com.mmy.service.impl.visa.VisaOrderServiceImpl;

/**
 * 类的介绍：签证订单
 *
 * @author shangzl
 * @date 创建日期：
 * @version 1.0
 */

@Controller
public class VisaOrderController {

	@Autowired
	VisaOrderServiceImpl visaOrderServiceImpl;
	@Autowired
	VisaBaseServiceImpl visaBaseServiceImpl;

	/**
	 * 函数功能说明： 前台个人中心点击取消船票预留
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/entervisacancelreserve")
	public String enterShipCancelReserve(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		visaOrderServiceImpl.updateState(iID, sessionSysUser);
		return "redirect:myvisareserve";
	}

	/**
	 * 函数功能说明： 前台个人中心点击申请签证退单
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/entervisaapplyrefund")
	public String enterVisaApplyRefund(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		visaOrderServiceImpl.updateRefundState(iID, sessionSysUser);
		return "redirect:myvisaorder";
	}

	/**
	 * 函数功能说明： 前台个人中心点击撤销签证退单
	 *
	 * @param 参数说明 tSysUser:用户类 用户 session
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.10.29
	 */
	@RequestMapping(value = "/entervisacancelrefund")
	public String enterVisaCancelRefund(HttpServletRequest request, HttpSession session) {

		int iID = Integer.parseInt(request.getParameter("iID"));
		TSysUser sessionSysUser = (TSysUser) session.getAttribute("tSysUser");
		visaOrderServiceImpl.updateCancelState(iID, sessionSysUser);
		return "redirect:myvisarefund";
	}

	/* 前台个人中心显示订单详情 */
	@RequestMapping(value = "/myvisainfo")
	public String toMyVisaInfo(HttpServletRequest request, Model model) {

		int iID = Integer.parseInt(request.getParameter("iID"));

		TVisaOrder dbVisaOrder = visaOrderServiceImpl.findByID(iID);
		model.addAttribute("dbVisaOrder", dbVisaOrder);

		String strOrderID = dbVisaOrder.getOrderID();
		int iVisaID = Integer.parseInt(strOrderID.substring(0, 9));

		VVisaBase dbVisaBase = visaBaseServiceImpl.findByVisaID(iVisaID);

		model.addAttribute("dbVisaBase", dbVisaBase);

		return "permanagement/MyVisaInfo";
	}
}
